def key(item):
    return item[0]


def updateDatabase(database, index, value):
    if index in database:
        database[index] += value
    else:
        database[index] = value


infoSize = int(input())
database = {}
for i in range(infoSize):
    info = list(map(int, input().split()))
    id = info[0]
    val = info[1]
    updateDatabase(database, id, val)

database = dict(sorted(database.items(), key=key))
for id in database:
    print(id, database[id])
